<?php     
$loader->requireOnce('ordo/Country.class.php');
$loader->requireOnce('ordo/Insurance.class.php');
$loader->requireOnce('ordo/Career.class.php');
$loader->requireOnce('ordo/QueueItem.class.php');
$loader->requireOnce('includes/PatientQueue/AbsQueue.class.php');
/**
 * Controller HIS Patient actions
 */
class C_RecentItem extends Controller { 	
	
	var $_db;
	
    function C_RecentItem ($template_mod = "general") {
        parent::Controller();
        $this->_db = $GLOBALS['frame']['adodb']['db'];   
    	if (Celini::getCurrentController() == 'RecentItem') {
			$menu =& Menu::getInstance();
			$menu->currentSection = 'patient';
		}    
        $this->template_mod = $template_mod;        
        $this->view->path = 'patient';
    } 

	public function actionGetRecentPatient() {
		$html = "<table class='grid' cellspacing='0' cellpadding='0'>";
		if ($this->_me->get_role() == 'doctor') {
			$response['header'] = L10nHelper::_("Latest patient examined");
			$result = ORDataObject::factory('TicketItem')->getRecentPatient($this->_me->get_person_id());
			$patientAction = Celini::link('viewMedicalRecord', 'Patient', true);
			foreach($result as $item) {
				$html .= "<tr> 
				              <td style='border: none;'>
				                  <a style='color: #339933' href='{$patientAction}patientId={$item['patient_id']}'>{$item['patient_code']}</a><br/>
				                  <a style='color: #339933' href='{$patientAction}patientId={$item['patient_id']}'>{$item['name']}</a>
				              </td>
						  </tr>";	
			}
		} elseif ($this->_me->get_role() == 'billing_user') {
			$response['header'] = L10nHelper::_("Latest patient collected");
			$result = ORDataObject::factory('PaymentCollection')->getRecentPatient($this->_me->get_person_id());
			$patientAction = Celini::link('viewClosedFrame', 'Cashier', true);
			foreach($result as $item) {
				$html .= "<tr> 
				              <td style='border: none;'>
				                  <a style='color: #339933' href='{$patientAction}ticketItemId={$item['ticket_item_id']}'>{$item['patient_code']}</a><br/>
				                  <a style='color: #339933' href='{$patientAction}ticketItemId={$item['ticket_item_id']}'>{$item['name']}</a>
				              </td>
						  </tr>";	
			}
		}		
		$html .= "</table>";
		$response['body'] = $html;
		return json_encode($response);
	}
}
?>